<template>
  <div>
    <Header title="会员类别"></Header>
    <div class="Order">
      <operate
        :isAddShow="isAddShow"
        :isSeniorShow="isSeniorShow"
        :isExportShow="isExportShow"
        placeholder="会员类别"
      ></operate>
      <table cellspacing="0">
        <tr>
          <th>编码</th>
          <th>等级名称</th>
          <th>所需经验值</th>
          <th>会员特价</th>
          <th>积分倍数</th>
          <th>操作</th>
        </tr>
        <tr v-for="item in viewData" :key="item._id">
          <td>{{ item.code }}</td>
          <td>{{ item.grade }}</td>
          <td>{{ item.requiredExperience }}</td>
          <td>{{ item.specialOffer | boolean2chinese }}</td>
          <td>{{ item.integral }}</td>
          <td>
            <span> 修改 </span>
            <span @click="delOne(item._id)"> 删除 </span>
          </td>
        </tr>
        <tr>
          <td colspan="9" style="border: 0; color: #000">
            <Footer :uurl="url"></Footer>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
import Header from "@/components/member/header";
import Footer from "@/components/member/footer";
import operate from "@/components/member/operate";
export default {
  data() {
    return {
      isAddShow: true,
      isSeniorShow: false,
      isExportShow: false,
      categoryData: [],
      viewData: [],
      totalNums: 0,
      totalPages: 0,
      pageNum: 1,
      url: "/gxjy/memberCategory",
    };
  },
  methods: {
    delOne(id) {
      this.$http.post(this.url + "/del", { _id: id }).then((ret) => {
        console.log(ret);
      });
      this.getData();
    },
    getData() {
      this.$http.get(this.url + "/all").then((ret) => {
        console.log(ret);
        // 全部数据
        this.categoryData = ret.data;
        // 总数据条数
        this.totalNums = this.categoryData.length;
        // 总页数
        this.totalPages = Math.ceil(this.totalNums / 10);
        // 可见的数据
        this.viewData = this.categoryData.splice((this.pageNum - 1) * 10, 10);
        this.$store.commit("common/setTotalNums", this.totalNums);
        this.$store.commit("common/setTotalPages", this.totalPages);
      });
    },
  },
  filters: {
    boolean2chinese(val) {
      if (!val) {
        return "不支持";
      }
      return "支持";
    },
  },
  beforeDestroy() {},
  created() {
    this.getData();
  },
  components: {
    Footer,
    Header,
    operate,
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/scss/table.scss";
</style>
